import { SceneEvent } from "../Event/SceneEvent";
import { EventManager } from "../Managers/EventManager";
import { ApplicationMediator } from "./ApplicationMediator";
import FScene from "./FScene";

export class Application {
    
    public static ClassName: string = "Application";
    public static SN_NUM: number = 0;
    public static START_TIME: number = 0;
    private static isInitialize: boolean = false;
    public static CurrentScene: FScene = null;
    private static mediator: ApplicationMediator;
    public static canvasScale: cc.Vec2 = cc.v2(1, 1);

    public static get Mediator () : ApplicationMediator{
        return this.mediator
    }
    

    public static init(): void {
        if (this.isInitialize) return;
        this.isInitialize = true;
        this.START_TIME = Date.now();
        this.mediator = new ApplicationMediator();
        this.mediator.initialize();
        // let gameContainer = document.getElementById("Cocos2dGameContainer");
        // let ww = gameContainer.style.width;
        // let hh = gameContainer.style.height;
        // ww = ww.replace("px", "");
        // hh = hh.replace("px", "");
        // this.canvasScale.x = Number(ww) / stageWidth();
        // this.canvasScale.y = Number(hh) / stageHeight();
    }
    public static setCurrentScene(scene: FScene): void {
        this.CurrentScene = scene;
        let canvas = scene.node.getComponent(cc.Canvas);
        if (canvas != null) {
            canvas.fitHeight = true;
            canvas.fitWidth = true;
        }
        EventManager.dispatchEvent(new SceneEvent(SceneEvent.SET_CURRENT_SCENE, null));
    }
    public static onCurrentSceneDestroy(): void {
        this.CurrentScene = null;
        EventManager.dispatchEvent(new SceneEvent(SceneEvent.DESTROY_CURRENT_SCENE, null));
    }


    
}
